package org.jeecg.modules.appuser.api.game;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.appuser.entity.*;
import org.jeecg.modules.appuser.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@Slf4j
@Api(tags = "app个人中心接口")
@RestController
@RequestMapping("/app/gamecenter/api")
public class GameCenterContrller {

    @Autowired
    @Lazy(true)
    private ITbUserSqtService tbUserSqtService;

    @Autowired
    @Lazy(true)
    private ITbUserLuckdrawDetailService tbUserLuckdrawDetailService;

    @Autowired
    @Lazy(true)
    private ITbUserIntegralDetailService tbUserIntegralDetailService;

    @Autowired

    private ITbUserIntegralService tbUserIntegralService;

    @Autowired
    private ITbUserGameBuidingService tbUserGameBuidingService;

    @Autowired
    private ITbUserIntegralConfigDetailService tbUserIntegralConfigDetailService;

    @Autowired
    private ITbUserUpgradeConfigService tbUserUpgradeConfigService;
    @Autowired
    @Lazy(true)
    private ITbUserLuckdrawService tbUserLuckdrawService;

    @Autowired
    private ITbUserGameUserShandwService tbUserGameUserShandwService;

    @AutoLog(value = "获取抽奖信息")
    @ApiOperation("获取抽奖信息")
    @PostMapping(value = "/getMyLuckDrawList")
    public  Result<?>  getMyLuckDrawList(String user_id,Integer luckdraw_type) {
        return   tbUserLuckdrawService.getUsableLuckDrawConfigList(user_id,luckdraw_type);
    }


    @AutoLog(value = "获取中奖信息")
    @ApiOperation("获取中奖信息")
    @PostMapping(value = "/getWinPrizeInfo")
    public  Result<?>  getWinPrizeInfo(TbUserLuckdraw tbUserLuckdraw) {
        return   tbUserLuckdrawService.getWinPrizeInfo(tbUserLuckdraw);
    }


    @AutoLog(value = "获取玩转中间的通知消息")
    @ApiOperation("获取玩转中间的通知消息")
    @PostMapping(value = "/getGameCenterNotice")
    public  Result<?>  getGameCenterNotice() {
        return   tbUserLuckdrawService.getGameCenterNotice();
    }

    @AutoLog(value = "获取抽奖列表信息")
    @ApiOperation("获取抽奖列表信息")
    @PostMapping(value = "/getLuckDrawList")
    public  Result<?>  getLuckDrawList() {
        return   tbUserLuckdrawService.getLuckDrawList();
    }



    @AutoLog(value = "创建盖楼")
    @ApiOperation("创建盖楼")
    @PostMapping(value = "/createGameBuilding")
    public Result<?> createGameBuilding(String user_id, Integer type) {

        return tbUserGameBuidingService.createBuilding(user_id, type);
    }


    @AutoLog(value = "升级")
    @ApiOperation("升级")
    @PostMapping(value = "/upgradeGameBuilding")
    public Result<?> upgradeGameBuilding(String user_id,Integer type) {

        return tbUserSqtService.upgradeGameBuilding(user_id,type);
    }

    @AutoLog(value = "获取下一级规则")
    @ApiOperation("获取下一级规则")
    @PostMapping(value = "/getNextUpgradeGameBuilding")
    public Result<?> getNextUpgradeGameBuilding(Integer sort, Integer type) {
        return tbUserUpgradeConfigService.getNextUpgradeGameBuilding(sort,type);
    }


    @AutoLog(value = "参与抽奖")
    @ApiOperation("参与抽奖")
    @PostMapping(value = "/joinLuckDraw")
    public Result<?> joinLuckDraw(TbUserLuckdrawDetail tbUserLuckdrawDetail) {
        return tbUserLuckdrawDetailService.joinLuckDraw(tbUserLuckdrawDetail);
    }


    @AutoLog(value = "显示周签到信息")
    @ApiOperation("显示周签到信息")
    @PostMapping(value = "/showSignInDatabyWeek")
    public Result<?> showSignInDatabyWeek(String user_id) {

        return tbUserIntegralService.showSignInDatabyWeek(user_id);
    }

    @AutoLog(value = "积分兑换营业时间")
    @ApiOperation("积分兑换营业时间")
    @PostMapping(value = "/integralExchangeBizHours")
    public  Result<?> integralExchangeBizHours(String user_id, BigDecimal integral) {

        return tbUserIntegralService.integralExchangeBizHours(user_id, integral);
    }


    @AutoLog(value = "积分明细")
    @ApiOperation("积分明细")
    @PostMapping(value = "/getIntegralDetails")
    public Result<?> getIntegralDetails(TbUserIntegralDetail tbUserIntegralDetail,
                                        @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {

        Page<TbUserIntegralDetail> page = new Page<TbUserIntegralDetail>(pageNo, pageSize);
        IPage<TbUserIntegralDetail> pageList = tbUserIntegralDetailService.getIntegralDetails(page, tbUserIntegralDetail);
        return Result.ok(pageList);
    }


    @AutoLog(value = "获取用户的所有任务")
    @ApiOperation("获取用户的所有任务")
    @PostMapping(value = "/getLoginUserAllTasks")
    public Result<?> getLoginUserAllTasks(String user_id) {

        return tbUserIntegralConfigDetailService.getLoginUserAllTasksAndIntegral(user_id);
    }


    @AutoLog(value = "获取盖楼首页数据")
    @ApiOperation("获取盖楼首页数据")
    @PostMapping(value = "/getGameBuildingData")
    public Result<?> getGameBuildingData(String user_id, Integer type) {

        return tbUserGameBuidingService.getGameBuildingData(user_id, type);
    }

    @AutoLog(value = "获取闪电玩有些列表")
    @ApiOperation("获取闪电玩有些列表")
    @PostMapping(value = "/getShandwGameList")
    public Result<?> getShandwGameList(String user_id) {
        if(StringUtils.isEmpty(user_id)){
            return Result.error("参数错误");
        }
        return  tbUserGameUserShandwService.getShandwGameList(user_id);
    }

    @AutoLog(value = "赠送SQT")
    @ApiOperation("赠送SQT")
    @PostMapping(value = "/giveFirstSQT")
    public Result<?> giveFirstSQT(String user_id) {

        return tbUserSqtService.giveFirstSQT(user_id);
    }

    @AutoLog(value = "赠送100分钟营业时间")
    @ApiOperation("赠送100分钟营业时间")
    @PostMapping(value = "/give100Hours")
    public synchronized  Result<?> give100Hours(String user_id) {

        return tbUserGameBuidingService.give100Hours(user_id);
    }



}
